import { createStore } from 'vuex'

export default createStore({
  state: {
    cartList:[], // 购物车的数据
  },
  mutations: {
    addCart(state,val){
      let index = state.cartList.findIndex(item => item.ties == val.ties);
      if (index>-1){
        state.cartList[index].buyNum += val.buyNum;
      } else {
        state.cartList.push(val);
      }
    },
    checkAll(state,bool){ // 全选
      state.cartList.forEach(item => {
        item.isCheck = bool
      })
    },
    delect(state){ // 删除订单
      state.cartList = state.cartList.filter(item => item.isCheck==false);
    }
  },
  actions: {
  },
  modules: {
  }
})
